package com.meeting.controller;

import com.meeting.dto.RegisterDTO;
import com.meeting.service.CustomerService;
import com.meeting.service.EmpService;
import com.meeting.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "认证接口")
@Slf4j
public class AuthController {

    @Autowired
    private CustomerService customerService;
    
    @Autowired
    private EmpService empService;
    
    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public Result register(@RequestBody RegisterDTO registerDTO) {
        log.info("用户注册请求：{}", registerDTO);
        
        // 验证角色字段
        if (registerDTO.getRole() == null || registerDTO.getRole().isEmpty()) {
            return Result.error("请选择注册角色");
        }
        
        // 根据角色调用不同的服务
        if ("customer".equals(registerDTO.getRole())) {
            return customerService.register(registerDTO);
        } else if ("emp".equals(registerDTO.getRole())) {
            return empService.register(registerDTO);
        } else {
            return Result.error("无效的角色类型");
        }
    }
} 